import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22652
 * Date: 2024-05-16
 * Time: 23:03
 */
public class Merge {
    public static void merge(int[] nums1, int m, int[] nums2, int n) {
        int num=m+n-1;
        int i=m-1;
        int j=n-1;
        while(i>0&&j>0){
            if (nums1[i]>nums2[j]){
                nums1[num]=nums1[i];
                num--;
                i--;
            }else {
                nums1[num]=nums2[j];
                num--;
                j--;
            }
        }
        while(i>=0){
            nums1[num]=nums1[i];
            num--;
            i--;
        }
        while(j>=0){
            nums1[num]=nums2[j];
            num--;
            j--;
        }
    }
    public static void main(String[] args) {
        int[] num1=new int[]{0,0,0,0,0,0,0,0,0};
        int[] num2=new int[]{1,1,1};
        System.out.println(Arrays.toString(num1));
        merge(num1,0,num2,1);
        System.out.println(Arrays.toString(num1));
    }
}
